Loading necessary libraries
library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.4.4 ✔ purrr 1.0.2
✔ tibble 3.2.1 ✔ dplyr 1.1.4
✔ tidyr 1.3.0 ✔ stringr 1.5.1
✔ readr 2.1.4 ✔ forcats 1.0.0
── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
library(visdat)
library(missForest)
library(corrplot)
corrplot 0.92 loaded
library(mice)
Attaching package: ‘mice’
The following object is masked from ‘package:stats’:
filter
The following objects are masked from ‘package:base’:
cbind, rbind
library(car)
Loading required package: carData
Attaching package: ‘car’
The following object is masked from ‘package:dplyr’:
recode
The following object is masked from ‘package:purrr’:
some
library("MVA")
Loading required package: HSAUR2
Loading required package: tools
Attaching package: ‘HSAUR2’
The following object is masked from ‘package:mice’:
toenail
The following object is masked from ‘package:tidyr’:
household
library(tidyverse)
library(psych)
Attaching package: ‘psych’
The following object is masked from ‘package:car’:
logit
The following objects are masked from ‘package:ggplot2’:
%+%, alpha
library(naniar)
options(scipen=999)
Combining two sets of data
data <- read.csv("data.csv")
data
Add region categorical variable
library(countrycode)
countries <- c(data$country)
data$region <- countrycode(sourcevar = countries,
origin = "country.name",
destination = "region")
Warning: Some values were not matched unambiguously: European Union
library(choroplethr)
Loading required package: acs
Loading required package: XML
Attaching package: ‘XML’
The following object is masked from ‘package:tools’:
toHTML
Attaching package: ‘acs’
The following object is masked from ‘package:dplyr’:
combine
The following object is masked from ‘package:base’:
apply
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Stuck? Ask a question here: https://stackoverflow.com/questions/tagged/choroplethr.
library(WDI)
choroplethr_wdi(code="SH.STA.MMRT", year=2018, title="2018 Maternal Mortality Ratio", num_colors=1)
Warning: Please use ISO-2, ISO-3, or World Bank regional codes. Some of the country codes that you requested are invalid: NA, EH, AQWarning: The following regions were missing and are being set to NA: namibia, western sahara, taiwan, antarctica, kosovo
choroplethr_wdi(code="SP.DYN.TFRT.IN", year=2018, title="2018 Total Fertility Rate", num_colors=1)
Warning: Please use ISO-2, ISO-3, or World Bank regional codes. Some of the country codes that you requested are invalid: NA, EH, AQWarning: The following regions were missing and are being set to NA: namibia, western sahara, taiwan, antarctica, kosovo
choroplethr_wdi(code="SH.XPD.PVTD.PC.CD", year=2018, title="2018 Private Health Expenditure", num_colors=9)
Warning: Please use ISO-2, ISO-3, or World Bank regional codes. Some of the country codes that you requested are invalid: NA, EH, AQWarning: The following regions were missing and are being set to NA: namibia, north korea, western sahara, somaliland, somalia, syria, taiwan, yemen, antarctica, kosovo, libya
Remove rows that have more than 50% missing data.
final_df <- data[rowSums(is.na(data)) < ncol(data)/2, ]
final_df
miss_var_summary(final_df)
vis_miss(final_df)
Imputing missing data
categorical <- subset(data_after_mice, select = c(region, country, country_code))
non_categorical <- subset(data_after_mice, select = -c(region, country, country_code))
res <- cor(non_categorical)
corrplot(res, type = "upper", order = "hclust",
tl.col = "black", tl.srt = 45,col = COL2('PuOr', 10))
Remove variables that present multicollinearity
no_controls = subset(data_after_mice, select = -c(region, country, country_code))
vif_fun <- function(df, keep_in) {
# df: the dataset of interest
# keep_in: the variables that should be kept in
highest <- c()
while(TRUE) {
# the rnorm() below is arbitrary as the VIF should not
# depend on it
vifs <- vif(lm(rnorm(nrow(df)) ~. , data = df))
adj_vifs <- vifs[-which(names(vifs) %in% keep_in)]
if (max(adj_vifs) < 10) {
break
}
highest <- c(highest,names((which(adj_vifs == max(adj_vifs)))))
cat("\n")
cat("removed:", highest)
cat("\n")
df <- df[,-which(names(df) %in% highest)]
}
cat("\n")
cat("final variables: \n")
return(names(vifs))
}
vif_fun(no_controls,keep_in = c("gdp","fertility_rate","skilled_health_staff","mmr"))
removed: total_health_exp
removed: total_health_exp oop_health_exp
final variables:
[1] "govt_health_exp" "comp_educ" "mmr" "gdp" "gdp_per_capita" "private_health_exp"
[7] "fertility_rate" "sab" "num_physicians" "rule_of_law" "female_pop"
data_after_vif <- subset(data_after_mice, select = -c(total_health_exp, oop_health_exp))
noncategorical <- subset(data_after_vif, select = -c(region, country, country_code))
boxplot(noncategorical, use.cols = TRUE, las=2)
for (i in 1:ncol(noncategorical)){
plot(noncategorical[,i], noncategorical$mmr,
xlab=colnames(noncategorical)[i], ylab="MMR", pch=19)
}
Remove export_val_ind outliers
data_transformed <- data_after_mice
data_transformed$gdp_transform <- log(data_after_mice$gdp)
data_transformed$fertility_rate_transform <- log(data_after_mice$fertility_rate)
data_transformed$mmr_transform <- log(data_after_mice$mmr)
data_transformed$female_pop_transform <- log(data_after_mice$female_pop)
data_transformed$govt_health_transform <- log(data_after_mice$govt_health_exp)
data_transformed$gpd_pc_transform <- log(data_after_mice$gdp_per_capita)
data_transformed$private_health_transform <- log(data_after_mice$private_health_exp)
data_after_mice$gdp_transform <- log(data_after_mice$gdp)
data_after_mice$fertility_rate_transform <- log(data_after_mice$fertility_rate)
data_after_mice$mmr_transform <- log(data_after_mice$mmr)
data_after_mice$female_pop_transform <- log(data_after_mice$female_pop)
data_after_mice$govt_health_transform <- log(data_after_mice$govt_health_exp)
data_after_mice$gpd_pc_transform <- log(data_after_mice$gdp_per_capita)
data_after_mice$private_health_transform <- log(data_after_mice$private_health_exp)
data_transformed <- subset(data_transformed, select = -c(female_pop, fertility_rate, mmr, gdp, govt_health_exp, gdp_per_capita, private_health_exp))
transformed_noncat <- subset(data_transformed, select = -c(region, country, country_code))
for (i in 1:ncol(transformed_noncat)){
plot(transformed_noncat[,i], transformed_noncat$mmr,
xlab=colnames(transformed_noncat)[i], ylab="MMR", pch=19)
}
boxplot(transformed_noncat, use.cols = TRUE, las=2)
baseline <- lm(mmr_transform ~ govt_health_transform + private_health_transform, data = data_after_mice)
summary(baseline)
Call:
lm(formula = mmr_transform ~ govt_health_transform + private_health_transform,
data = data_after_mice)
Residuals:
Min 1Q Median 3Q Max
-3.6261 -0.4506 0.0616 0.5454 2.0302
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.68130 0.20453 37.556 < 0.0000000000000002 ***
govt_health_transform -0.51465 0.05968 -8.624 0.00000000000000208 ***
private_health_transform -0.26739 0.07659 -3.491 0.000593 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.9053 on 198 degrees of freedom
Multiple R-squared: 0.7135, Adjusted R-squared: 0.7106
F-statistic: 246.6 on 2 and 198 DF, p-value: < 0.00000000000000022
baseline <- lm(mmr_transform ~ region + govt_health_transform + private_health_transform, data = data_after_mice)
summary(baseline)
Call:
lm(formula = mmr_transform ~ region + govt_health_transform +
private_health_transform, data = data_after_mice)
Residuals:
Min 1Q Median 3Q Max
-2.73803 -0.35778 0.04387 0.48433 2.35595
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.52269 0.23691 27.532 < 0.0000000000000002 ***
regionEurope & Central Asia -0.83576 0.17440 -4.792 0.00000330545 ***
regionLatin America & Caribbean 0.60639 0.18320 3.310 0.001115 **
regionMiddle East & North Africa -0.27143 0.20385 -1.332 0.184595
regionNorth America 0.41232 0.45156 0.913 0.362335
regionSouth Asia 0.27076 0.29298 0.924 0.356562
regionSub-Saharan Africa 1.00278 0.18587 5.395 0.00000020109 ***
govt_health_transform -0.33308 0.05293 -6.293 0.00000000208 ***
private_health_transform -0.24349 0.06486 -3.754 0.000231 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.7087 on 191 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.8295, Adjusted R-squared: 0.8223
F-statistic: 116.1 on 8 and 191 DF, p-value: < 0.00000000000000022
data_after_mice
baseline_contr_1 <- lm(mmr_transform ~ region + govt_health_transform + private_health_transform + gpd_pc_transform + gdp_transform + rule_of_law + comp_educ + female_pop_transform + fertility_rate_transform + sab, data = data_after_mice)
summary(baseline_contr_1)
Call:
lm(formula = mmr_transform ~ region + govt_health_transform +
private_health_transform + gpd_pc_transform + gdp_transform +
rule_of_law + comp_educ + female_pop_transform + fertility_rate_transform +
sab, data = data_after_mice)
Residuals:
Min 1Q Median 3Q Max
-2.55146 -0.33833 0.02559 0.41833 2.39345
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.488229 1.108982 5.851 0.000000022 ***
regionEurope & Central Asia -0.796719 0.169876 -4.690 0.000005311 ***
regionLatin America & Caribbean 0.608830 0.196094 3.105 0.002205 **
regionMiddle East & North Africa -0.410757 0.207745 -1.977 0.049511 *
regionNorth America 0.197179 0.427661 0.461 0.645297
regionSouth Asia 0.259955 0.278046 0.935 0.351048
regionSub-Saharan Africa 0.573976 0.199503 2.877 0.004489 **
govt_health_transform -0.210971 0.072638 -2.904 0.004130 **
private_health_transform -0.191597 0.075296 -2.545 0.011763 *
gpd_pc_transform 0.241784 0.194977 1.240 0.216531
gdp_transform -0.244131 0.168079 -1.452 0.148072
rule_of_law -0.017058 0.097380 -0.175 0.861137
comp_educ 0.020288 0.021599 0.939 0.348802
female_pop_transform 0.265336 0.167947 1.580 0.115852
fertility_rate_transform 0.730298 0.216996 3.365 0.000930 ***
sab -0.017295 0.004803 -3.601 0.000407 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6637 on 184 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.8559, Adjusted R-squared: 0.8442
F-statistic: 72.86 on 15 and 184 DF, p-value: < 0.00000000000000022
baseline_contr_2 <- lm(mmr_transform ~ region + govt_health_transform + private_health_transform + gdp_transform + fertility_rate_transform + sab, data = data_after_mice)
summary(baseline_contr_2)
Call:
lm(formula = mmr_transform ~ region + govt_health_transform +
private_health_transform + gdp_transform + fertility_rate_transform +
sab, data = data_after_mice)
Residuals:
Min 1Q Median 3Q Max
-2.52635 -0.35056 0.03425 0.43336 2.47912
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.077715 0.788813 7.705 0.000000000000731 ***
regionEurope & Central Asia -0.769487 0.163740 -4.699 0.000005029707029 ***
regionLatin America & Caribbean 0.687525 0.173052 3.973 0.000101 ***
regionMiddle East & North Africa -0.416990 0.195870 -2.129 0.034564 *
regionNorth America 0.234254 0.424062 0.552 0.581326
regionSouth Asia 0.269877 0.276803 0.975 0.330825
regionSub-Saharan Africa 0.530399 0.196446 2.700 0.007567 **
govt_health_transform -0.227863 0.053658 -4.247 0.000034093025032 ***
private_health_transform -0.191903 0.069811 -2.749 0.006563 **
gdp_transform 0.022464 0.024036 0.935 0.351194
fertility_rate_transform 0.740756 0.210669 3.516 0.000549 ***
sab -0.015892 0.004669 -3.404 0.000812 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.663 on 188 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.8531, Adjusted R-squared: 0.8445
F-statistic: 99.25 on 11 and 188 DF, p-value: < 0.00000000000000022
data_after_mice[data_after_mice$region == "East Asia & Pacific",]
NA
data_after_mice[data_after_mice$region == "Europe & Central Asia",]
NA
data_after_mice$spend_ratio <- data_after_mice$govt_health_transform/data_after_mice$private_health_transform
ratio_lm <- lm(mmr_transform ~ region + spend_ratio + govt_health_transform + private_health_transform + gdp_transform + fertility_rate_transform + sab, data = data_after_mice)
summary(ratio_lm)
Call:
lm(formula = mmr_transform ~ region + spend_ratio + govt_health_transform +
private_health_transform + gdp_transform + fertility_rate_transform +
sab, data = data_after_mice)
Residuals:
Min 1Q Median 3Q Max
-2.51519 -0.35391 0.03489 0.44213 2.42406
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.586261 0.927840 6.021 0.000000009 ***
regionEurope & Central Asia -0.736182 0.167049 -4.407 0.000017637 ***
regionLatin America & Caribbean 0.716565 0.175439 4.084 0.000065470 ***
regionMiddle East & North Africa -0.378378 0.199590 -1.896 0.059532 .
regionNorth America 0.240026 0.424087 0.566 0.572084
regionSouth Asia 0.308339 0.279423 1.103 0.271236
regionSub-Saharan Africa 0.594936 0.206651 2.879 0.004455 **
spend_ratio 0.325085 0.323178 1.006 0.315763
govt_health_transform -0.319462 0.105694 -3.023 0.002858 **
private_health_transform -0.085852 0.126446 -0.679 0.498003
gdp_transform 0.025871 0.024273 1.066 0.287872
fertility_rate_transform 0.728524 0.211013 3.453 0.000687 ***
sab -0.015959 0.004669 -3.418 0.000775 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.663 on 187 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.8539, Adjusted R-squared: 0.8445
F-statistic: 91.07 on 12 and 187 DF, p-value: < 0.00000000000000022
no_controls = subset(data_after_mice, select = -c(region, country, country_code))
vif_fun <- function(df, keep_in) {
# df: the dataset of interest
# keep_in: the variables that should be kept in
highest <- c()
while(TRUE) {
# the rnorm() below is arbitrary as the VIF should not
# depend on it
vifs <- vif(lm(rnorm(nrow(df)) ~. , data = df))
adj_vifs <- vifs[-which(names(vifs) %in% keep_in)]
if (max(adj_vifs) < 10) {
break
}
highest <- c(highest,names((which(adj_vifs == max(adj_vifs)))))
cat("\n")
cat("removed:", highest)
cat("\n")
df <- df[,-which(names(df) %in% highest)]
}
cat("\n")
cat("final variables: \n")
return(names(vifs))
}
vif_fun(no_controls,keep_in = c("gdp","fertility_rate","skilled_health_staff","mmr"))
removed: total_health_exp
removed: total_health_exp gdp_transform
removed: total_health_exp gdp_transform govt_health_transform
removed: total_health_exp gdp_transform govt_health_transform fertility_rate_transform
removed: total_health_exp gdp_transform govt_health_transform fertility_rate_transform gpd_pc_transform
removed: total_health_exp gdp_transform govt_health_transform fertility_rate_transform gpd_pc_transform oop_health_exp
final variables:
[1] "govt_health_exp" "comp_educ" "mmr" "gdp"
[5] "gdp_per_capita" "private_health_exp" "fertility_rate" "sab"
[9] "num_physicians" "rule_of_law" "female_pop" "mmr_transform"
[13] "female_pop_transform" "private_health_transform" "spend_ratio"
vifLm <- lm(mmr_transform~region + govt_health_transform + private_health_transform + gdp_transform + fertility_rate_transform + sab, data = data_after_mice)
plot(vifLm)
dfNoOutliers <- data_after_mice[-c(49,74,19),]
no_outliers_lm <- lm(mmr_transform ~ region + govt_health_transform + private_health_transform + gdp_transform + fertility_rate_transform + sab, data = dfNoOutliers)
summary(no_outliers_lm)
Call:
lm(formula = mmr_transform ~ region + govt_health_transform +
private_health_transform + gdp_transform + fertility_rate_transform +
sab, data = dfNoOutliers)
Residuals:
Min 1Q Median 3Q Max
-2.30588 -0.36768 0.02031 0.42348 1.32428
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 6.055698 0.701913 8.627 0.00000000000000281 ***
regionEurope & Central Asia -0.843949 0.148393 -5.687 0.00000004966615839 ***
regionLatin America & Caribbean 0.606159 0.156173 3.881 0.000144 ***
regionMiddle East & North Africa -0.507917 0.175939 -2.887 0.004354 **
regionNorth America 0.162204 0.377268 0.430 0.667736
regionSouth Asia 0.188490 0.245688 0.767 0.443945
regionSub-Saharan Africa 0.425876 0.176517 2.413 0.016812 *
govt_health_transform -0.233037 0.047900 -4.865 0.00000243956902508 ***
private_health_transform -0.184430 0.064100 -2.877 0.004483 **
gdp_transform 0.022147 0.021496 1.030 0.304221
fertility_rate_transform 0.791886 0.189802 4.172 0.00004635612096637 ***
sab -0.015200 0.004144 -3.668 0.000319 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.5869 on 185 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.8817, Adjusted R-squared: 0.8747
F-statistic: 125.3 on 11 and 185 DF, p-value: < 0.00000000000000022
ratio_lm <- lm(mmr_transform ~ region + spend_ratio + gpd_pc_transform + gdp_transform + rule_of_law + comp_educ + female_pop_transform + fertility_rate_transform + sab, data = dfAfterVIF)
Error in is.data.frame(data) : object 'dfAfterVIF' not found
interaction_lm <- lm(mmr_transform ~ region + govt_health_transform + private_health_transform + gdp_transform + fertility_rate_transform + sab + region*govt_health_transform + region*private_health_transform, data = data_after_mice)
summary(interaction_lm)
Call:
lm(formula = mmr_transform ~ region + govt_health_transform +
private_health_transform + gdp_transform + fertility_rate_transform +
sab + region * govt_health_transform + region * private_health_transform,
data = data_after_mice)
Residuals:
Min 1Q Median 3Q Max
-2.5588 -0.2828 0.0000 0.3913 1.9616
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.154288 0.837772 8.540 0.00000000000000617 ***
regionEurope & Central Asia -3.799619 0.659677 -5.760 0.00000003685332698 ***
regionLatin America & Caribbean 0.126602 0.802424 0.158 0.874815
regionMiddle East & North Africa -0.893621 0.703971 -1.269 0.205974
regionNorth America 37.722845 102.900300 0.367 0.714361
regionSouth Asia -1.841573 1.274540 -1.445 0.150266
regionSub-Saharan Africa -0.992494 0.520110 -1.908 0.057988 .
govt_health_transform -0.311804 0.103018 -3.027 0.002844 **
private_health_transform -0.416170 0.106797 -3.897 0.000138 ***
gdp_transform 0.030034 0.024604 1.221 0.223828
fertility_rate_transform 0.489113 0.215709 2.267 0.024578 *
sab -0.011995 0.004720 -2.541 0.011912 *
regionEurope & Central Asia:govt_health_transform -0.085542 0.147237 -0.581 0.561996
regionLatin America & Caribbean:govt_health_transform 0.074779 0.201933 0.370 0.711593
regionMiddle East & North Africa:govt_health_transform 0.113804 0.200934 0.566 0.571860
regionNorth America:govt_health_transform -7.577479 17.348659 -0.437 0.662809
regionSouth Asia:govt_health_transform -0.006341 0.196097 -0.032 0.974239
regionSub-Saharan Africa:govt_health_transform -0.035198 0.143883 -0.245 0.807028
regionEurope & Central Asia:private_health_transform 0.666131 0.180003 3.701 0.000287 ***
regionLatin America & Caribbean:private_health_transform 0.065048 0.217825 0.299 0.765580
regionMiddle East & North Africa:private_health_transform 0.008531 0.243012 0.035 0.972037
regionNorth America:private_health_transform 3.431308 5.407290 0.635 0.526532
regionSouth Asia:private_health_transform 0.502385 0.375367 1.338 0.182498
regionSub-Saharan Africa:private_health_transform 0.435495 0.165936 2.624 0.009441 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6268 on 176 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.8771, Adjusted R-squared: 0.861
F-statistic: 54.6 on 23 and 176 DF, p-value: < 0.00000000000000022
my.cols <- c("#0a0a0a","#8087A3","#656191","#384c9c","#80808c","#edb880","#ed8618")
my.names <- c("Germay","Poland","France","Italy","United.States","United.Kingdom","Greece")
names(my.cols) <- my.names
mmr_time <- read.csv("mmr_time.csv")
p <- ggplot(mmr_time, aes(x = Time))
mmr_time
library("tidyverse")
df <- mmr_time %>%
rename(
USA = United.States,
UK = United.Kingdom
)
df <- df %>%
select(Time, Germany, Poland, France,Italy,USA,UK,Greece) %>%
gather(key = "variable", value = "value", -Time)
head(df)
NA
ggplot(df, aes(x = Time, y = value)) +
geom_line(aes(color = variable)) +
scale_color_manual(labels=c("France","Germany","Greece","Italy","Poland","United.Kingdom","United.States"),values = c("#0a0a0a","#c8c8cc","#9f9dd1","#4d49b8","#f76902","#edb880","#ed8618")) +
theme_bw() +
labs(x = "Year", y = "MMR", color = "Country")
my.cols <- c("#0a0a0a","#8087A3","#656191","#384c9c","#80808c")
my.names <- c("USA", "EUU")
names(my.cols) <- my.names
govt_exp <- read.csv("govt_exp_time.csv")
p <- ggplot(govt_exp, aes(x = Year))
for (i in 1:2){
p <- p + geom_line(aes_(y = as.name(names(govt_exp[i+1])), colour =
colnames(govt_exp[i+1])))
}
p + scale_colour_manual("",
breaks = as.character(my.names),
values = my.cols) + labs(y= "Government Health Expenditure Per Capita (Current US $)")
p
my.cols <- c("blue","orange")
my.names <- c("USA", "EUU")
names(my.cols) <- my.names
priv_exp <- read.csv("private_exp_time.csv")
p <- ggplot(priv_exp, aes(x = Year))
for (i in 1:2){
p <- p + geom_line(aes_(y = as.name(names(priv_exp[i+1])), colour =
colnames(priv_exp[i+1])))
}
p + scale_colour_manual("",
breaks = as.character(my.names),
values = my.cols) + labs(y= "Private Health Expenditure Per Capita (Current US $)")
p